set -e

source ./make_openssl_3.0.7.sh

for i in {1..10000}
do
    $openssl genrsa -out rsakey.pem 2048
    $openssl rsa -in rsakey.pem -text -noout -out keypair.txt
    TrimOpensslText keypair.txt
    private_exponent=$(GetNthLine keypair.txt 6)
    echo $private_exponent
    private_exponent_text_len=$(echo -n $private_exponent | wc -c)
    private_exponent_byte_len=$(($private_exponent_text_len / 2))
    echo "private_exponent_byte_len = $private_exponent_byte_len"
    if [ $private_exponent_byte_len -lt 256 ]
    then
        echo "!!!!found!!!! iteration times: " $i
        break
    fi
done

cat rsakey.pem
$openssl rsa -in rsakey.pem -outform DER -out rsakey.der
FileHexDump rsakey.der

$openssl rsa -in rsakey.pem -pubout -out rsapubkey.pem
cat rsapubkey.pem
$openssl rsa -pubin -in rsapubkey.pem -outform DER -out rsapubkey.der
FileHexDump rsapubkey.der
